package com.future.controller;

import javax.validation.constraints.NotNull;

import com.future.common.annotation.ControllerMapping;
import com.future.common.annotation.NoNeedLogin;
import com.future.common.base.BaseController;
import com.future.service.AuthenticationService;
import com.jfinal.aop.Inject;

/**
 * 认证处理器
 * 
 * @author Leon.Zhang
 *
 */
@ControllerMapping("/authen")
public class AuthenticationController extends BaseController {
	@Inject
	private AuthenticationService authenticationService;
	/**
	 * 认证
	 */
	@NoNeedLogin
	public void getToken(@NotNull(message="用户名为空!")String userName, @NotNull(message="密码为空!")String password) {
		String token = this.authenticationService.getToken(userName, password);
		renderResult("token", token);
	}

	/**
	 * token刷新
	 * 
	 * @param token
	 */
	public void refreshtoken() {
		String token = getRequest().getHeader("Authorization");
		String refreshToken = this.authenticationService.refreshToken(token);
		renderResult("token", refreshToken);
	}
}
